package com.groupbuying.cheetah.sysconfig.opexRule;

import com.groupbuying.cheetah.common.FilterContextHandler;
import com.groupbuying.cheetah.common.PageUtils;
import com.groupbuying.cheetah.common.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/opexRuleWithProvider")
public class OpexRuleController {

  @Autowired
  private OpexRuleDAO opexRuleDAO;

  @GetMapping("/listWithStoreInfo")
  public PageUtils listWithStoreInfo() {

    Map<String, Object> params = new HashMap<>();
    String providerId = FilterContextHandler.getName();
    //providerId = "191000030001";
    params.put("providerId", providerId);
    Query query = new Query(params);
    List<Map<String,String>> resultList = opexRuleDAO.listWithStoreInfo(query);
    int total = opexRuleDAO.count(params);
    PageUtils pageUtils = new PageUtils(resultList, total);
    return pageUtils;

  }

  @GetMapping("/bindStoreOpexRule")
  public int updateStoreOpexRule(@RequestParam String storeId, @RequestParam String ruleId) {

    return opexRuleDAO.bindStoreOpexRule(storeId, ruleId);

  }

}
